import React from 'react';
import { connect } from 'dva';
import { Button } from 'antd';

const dva = (
  props: any,
  {
    // tags,
    // dispatch
  }: any
) => {

  const { dispatch } = props

  // useEffect(() => {
  //   dispatch({
  //     type: 'tags/fetchTags',
  //     payload: null
  //   }).then((res: any) => {
  //     // console.log(res);
  //     console.log(tags?.tagList, 'props');
  //
  //   })
  // }, []);

  const list = props?.tags?.tagList?.list || []

  console.log(props?.tags?.tagList?.list, 'props');

  const getData = () => {
    dispatch({
      type: 'tags/fetchTags',
      payload: null
    })
  }


  return (
    <div>
      <h1>DVA的使用</h1>
      <Button onClick={getData}>获取Tags</Button>
      {
        list.map((item: {
          name: string | number | null | undefined;
          value: React.Key | null | undefined; }, index: any) => {
          console.log(item.name+index);
          return <p key={item.name+index}>{item.name}</p>
        })
      }
    </div>
  );
};

export default connect(({ tags }: any) => ({
  tags,
}))(dva);
